<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib  uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="static/easyui/jquery.min.js"></script>
<script type="text/javascript" src="static/easyui/jquery.easyui.min.js"></script>
<script type="text/javascript" src="static/easyui/locale/easyui-lang-zh_CN.js"></script>
<link rel="stylesheet" href="static/easyui/themes/metro/easyui.css"/>
<link rel="stylesheet" href="static/easyui/themes/icon.css"/>
<title>挂号管理</title>
</head>
<body>
<script type="text/javascript">
		$(function(){
		 //打印小票
       	 $("#click-ticket").click(function(){
       	    $(".window-tishi").text("正在打印小票,请稍后......");
	    	$("#saveclinic-winTwo").window('open');
	    	//三秒之后自动消失
		   setTimeout(function(){
		    	  $("#saveclinic-winTwo").window('close');
		    	  $("#ticket-registr-win").window('open');
		    		 $.ajax({
		     			 url:'Registr-Ticket',
		     			 type:'post',
		     			 dataType:'json',
		     			 success:function(data){
		     				 //姓名
		     	       		 $("#ticket_uname").text(data[0]["clinic_name"]);
		    	       		 //性别
		    	       		 $("#ticket_usex").text(data[0]["clinic_sex"]);
		    	       		 //科室
		    	       		 $("#ticket_usection").text(data[0]["section_name"]);
		    	       		 //挂号类型
		    	       		 $("#ticket_uregtype").text(data[0]["registrtype_name"]);
		     	       		 //挂号费用
		    	       		 $("#ticket_umoney").text(data[0]["registrtype_price"]);
		     	       		 //看诊费用
		     	       		 $("#ticket_ulookmoney").text(data[0]["registrfrom_lookmoney"]);
		     	       		 //流水单号
		     	       		 $("#regwaternumber").text(data[0]["regwaternumber"]);
		     	       		 //时间
		     	       		 $("#regdate").text(comFormatDate(data[0]["registrform_time"]));
		     	       		//共计
		     	       		var registrtype_price=data[0]["registrtype_price"];
		     	       		var registrfrom_lookmoney=data[0]["registrfrom_lookmoney"];
		     	       		var totals=parseInt(registrtype_price)+parseInt(registrfrom_lookmoney);
		     	       		console.log("共计-------------------:"+totals);
		    	       		$("#ticket_utotalmoney").text(parseInt(totals));
		                 //经办人
		     	       	   $("#ticket_uregpeople").text(data[0]["registrfrom_name"]);
		     			 }
		     		 });
			  }, 3000);
	    	
		   setTimeout(function(){
		    	  $("#ticket-registr-win").window('close');
		    }, 7000);
       	 });
			
			
			//根据医疗卡填充信息
			$("#cliniccardid").searchbox({
				searcher:function(value,name){
					var cid = value  //获取医疗卡号
					$.ajax({
		                url:'find-cliniccardid',
		                type:"post",
		                data:{'cliniccardid':cid},
		                dataType:"json",
		                success:function(data) {
		                     console.log(data.cliniccardid);
		                     if(data.cliniccardid.length==0){
		                    	 $.messager.confirm('Confirm', 
		     							'无此医疗卡号', 
		     							function(r){
		     					});
		                     }
		                     
		                    //患者姓名
		                     $("#ucliickuname").textbox('setValue',data.cliniccardid[0]['clinicName']); 
		                    //患者性别
		                    $("#uclick-usex").combobox('setValue',data.cliniccardid[0]['clinicSex']);
		                    //身份证号
		                    $("#ucliickucard").textbox('setValue',data.cliniccardid[0]['clinicIdnumber']);
		                    //手机号码
		                    $("#ucliickutel").textbox('setValue',data.cliniccardid[0]['clinicTel']);
		                    //余额
		                    $("#shyumoneys").textbox('setValue',data.cliniccardid[0]['clinicRemainmoney']);
		                    
		                },
		                error:function() {
		                     
		                }
		            });
				}
			});
			
			//医疗卡与姓名查询
			$("#regsreachbox").searchbox({
				searcher:function(value){
					//alert(value);
					//访问数据源、初始化表格
					$('#registration-tab').datagrid({
					    url:'selectAll-registr',
					    queryParams:{
					    	/* cliniccardid:value */
					    	clinicname:value 
					    },
					    pagination:true,
					    pageNumber:1,
					    pageSize:3,
					    pageList:[3,2],
					    columns:[[
					    	{field:'cliniccard_id',title:'医疗卡号',width:140},
							{field:'clinic_name',title:'病人姓名',width:140},
							{field:'clinic_sex',title:'性别',width:120},
							{field:'clinic_idnumber',title:'身份证号',width:170},
							{field:'section_name',title:'接诊科室',width:160},
							{field:'registrform_time',title:'时间',width:198,
								formatter:comFormatDate
							}
					    ]]
					});
				}
			});
			
			
			//挂号记录初始化
			 $('#registration-tab').datagrid({
			     url:'selectAll-registr',
			     pagination:true,
				 pageNumber:1,
				 pageSize:3,
				  pageList:[3,2],
			     columns:[[
			    	    {field:'cliniccard_id',title:'医疗卡号',width:140},
						{field:'clinic_name',title:'病人姓名',width:140},
						{field:'clinic_sex',title:'性别',width:120},
						{field:'clinic_idnumber',title:'身份证号',width:170},
						{field:'section_name',title:'接诊科室',width:160},
						{field:'registrform_time',title:'时间',width:198,
							formatter:comFormatDate
						}
			    ]]
			});
			 
			 
				//挂号取消按钮
				$("#click-nos").click(function(){
					//只会清空日期框，不会清空combobox。
					$('#form-mregistr').form('reset');
				});
				
				//挂号确定提交
				$("#click-yess").click(function(){
					$('#form-mregistr').form({    
					    url:'add-registrfrom',    
					    onSubmit: function(){    
					        // 执行验证    
					        var c=$('#form-mregistr').form("validate");
					        return c;
					    }, 
					    //表单提交成功之后的数据
					    success:function(data){
					        $(".window-tishi").text("挂号成功,正在打印小票,请稍后......");
					    	$("#saveclinic-winTwo").window('open');
					    	setTimeout(function(){
					    		$("#saveclinic-winTwo").window('close');
					    		$("#ticket-registr-win").window('open');
						    }, 3000);
					    		 $.ajax({
					     			 url:'Registr-Ticket',
					     			 type:'post',
					     			 dataType:'json',
					     			 success:function(data){
					     				 //姓名
					     	       		 $("#ticket_uname").text(data[0]["clinic_name"]);
					    	       		 //性别
					    	       		 $("#ticket_usex").text(data[0]["clinic_sex"]);
					    	       		 //科室
					    	       		 $("#ticket_usection").text(data[0]["section_name"]);
					    	       		 //挂号类型
					    	       		 $("#ticket_uregtype").text(data[0]["registrtype_name"]);
					     	       		 //挂号费用
					    	       		 $("#ticket_umoney").text(data[0]["registrtype_price"]);
					     	       		 //看诊费用
					     	       		 $("#ticket_ulookmoney").text(data[0]["registrfrom_lookmoney"]);
					     	       		 //流水单号
					     	       		 $("#regwaternumber").text(data[0]["regwaternumber"]);
					     	       		 //时间
					     	       		 $("#regdate").text(comFormatDate(data[0]["registrform_time"]));
					     	       		//共计
					     	       		var registrtype_price=data[0]["registrtype_price"];
					     	       		var registrfrom_lookmoney=data[0]["registrfrom_lookmoney"];
					     	       		var totals=parseInt(registrtype_price)+parseInt(registrfrom_lookmoney);
					     	       		console.log("共计-------------------:"+totals);
					    	       		$("#ticket_utotalmoney").text(parseInt(totals));
					                 //经办人
					     	       	   $("#ticket_uregpeople").text(data[0]["registrfrom_name"]);
					     			 }
					     		 });
					    	
						    setTimeout(function(){
						    	  $("#ticket-registr-win").window('close');
						    }, 7000);
					        /* $(".window-tishi").text("当前该病人已经挂号成功！！！");
					    	$("#saveclinic-winTwo").window('open');
					    	//三秒之后自动消失
						   setTimeout(function(){
						    	 $("#saveclinic-winTwo").window('close');
							  }, 3000); */
					   	    $('#registration-tab').datagrid('reload');
					   	    $('#sections').combobox('reload');
					   	    $('#registration-type').combobox('reload');
					   	    $("#cliniccardid").textbox('setValue',''); 
					   	    $("#ucliickutel").textbox('setValue','');
		                    $("#ucliickuname").textbox('setValue',''); 
		                    $("#ucliickucard").textbox('setValue','');
					    }    
					}).submit();  
					
				});			
				
				
				//初始化科室下拉表的数据
				  $('#sections').combobox({   
		         	url:'init-section',//数据源
		         	valueField: 'sectionId',//实体类名字---主键id
			        textField: 'sectionName',//需要显示在下拉框的实际内容
			        editable:false,
		            panelHeight:'auto',//高度根据内容自动定
		            onSelect:function(r){//下拉选中事件
					      var m= r["sectionId"]; 
				          $("#sectionmoney").textbox('setValue',m); 
				          /* alert("挂号类型id："+r["registrtypeId"]); */
				     } , 
		            onLoadSuccess: function () {  //加载完成后,设置选中第一项
		                    var val = $(this).combobox("getData");
		                    for (var item in val[0]) {
		                        if (item == "sectionId") {
		                        	//初始化数据默认选中第一个
		                            $(this).combobox("select", val[0][item]);
		                        }
		                    }
		             }
	 
		            });
			
				//初始化挂号类型下拉表的数据
				$('#registration-type').combobox({   
		         	url:'init-regstrtype',//数据源
		         	valueField: 'registrtypeId',//实体类名字---主键id
			        textField: 'registrtypeName',//需要显示在下拉框的实际内容
			        editable:false,
		            panelHeight:'auto',//高度根据内容自动定
		            onSelect:function(r){//下拉选中事件
					      var s= r["registrtypeId"]; 
				          $("#sreg-type").textbox('setValue',s); 
				          /* alert("挂号类型id："+r["registrtypeId"]); */
				     } , 
		            onLoadSuccess: function () {  //加载完成后,设置选中第一项
		            	var val= $(this).combobox("getData");
		                //判断是否门诊与急诊来分别选中 
		        	    $.ajax({
	            	    	url:'If-emergency',
	            	    	type:'post',
	            	    	success:function(data){
	            	    		if(parseInt(data)==1){
	      		                      for (var item in val[1]) {
	      		                        if (item == "registrtypeId") {
	      		                        	//alert("1:"+val[1][item]);
	      		                        	//选中第2个
	      		                            $("#registration-type").combobox("select", val[1][item]);
	      		                            $("#registration-type").combobox('readonly',true); 
	      		                        }
	      		                    }
	            	    		}//1
	            	    		if(parseInt(data)==2){
	      		                      for (var item in val[0]) {
	      		                        if (item =="registrtypeId") {
	      		                        	//选中第一个
	      		                            $("#registration-type").combobox("select", val[0][item]);
	      		                        }
	      		                    }
	            	    		}//2
	            	    	}
	            	    });
		                
		             }
	 
		            });
				
		});
		
		//格式化时间
		function comFormatDate(date) {
			var day = new Date(date); 
			var Year = 0; 
			var Month = 0; 
			var Day = 0; 
			var CurrentDate = ""; 
			//初始化时间 
			Year= day.getFullYear();//ie火狐下都可以 
			Month= day.getMonth()+1; 
			Day = day.getDate(); 
			Hour = day.getHours(); 
			 Minute = day.getMinutes(); 
			 Second = day.getSeconds(); 
			CurrentDate += Year + "-"; 
			if (Month >= 10 ) { 
				CurrentDate += Month + "-"; 
			}else { 
				CurrentDate += "0" + Month + "-"; 
			} 
			if (Day >= 10 ) { 
				CurrentDate += Day ; 
			}else { 
				CurrentDate += "0" + Day ; 
			} 
			if(Hour>=10){
				CurrentDate +=" "+Hour;
			}else{
				CurrentDate +=" "+"0"+Hour;
			}
			if(Minute>=10){
				CurrentDate +=":"+Minute;
			}else{
				CurrentDate +=":"+"0"+Minute;
			}
			if(Second>=10){
				CurrentDate +=":"+Second;
			}else{
				CurrentDate +=":"+"0"+Second;
			}
			return CurrentDate; 
		}
		
		//支付方式下拉事件
		function selecttype(val){
			 if(val==0){//0为医疗卡
				 //获取挂号类型
				 var  regstrtypeid=$("#sreg-type").textbox("getValue");
			    //获取所挂科室
			     var  sectionid=$("#sectionmoney").textbox("getValue");
				 //获取用户余额
				 var yumoney=$("#shyumoneys").val();
				 //alert("余额："+yumoney+"--------挂号类型："+regstrtypeid+"--------挂号科室："+sectionid);
				  $.ajax({
					    type:'post',
					    url:'init-money',
					    data:{"regstrtypeid":regstrtypeid,"yumoney":yumoney,"sectionid":sectionid},
					    success:function(data){
					    	if(data==1 || data==2){
					    		$.messager.confirm('Confirm', 
										'余额不足,请前往医疗卡管理进行充值', 
										function(r){
								});
					    	}
					    }
				 });
			 }
		}
		
</script>
  <!-- 北 -->
 <!--  挂号收取看诊费用和挂号费用 -->
    <div class="registeration easyui-panel" data-options="fit:true,border:false ,region:'north'" >
      <input class="easyui-textbox" id="sreg-type" type="hidden" >
      <input class="easyui-textbox" id="sectionmoney" type="hidden" >
     <!--   <div class="register-topbox2" data-options="fit:true">挂号信息</div> -->
     <fieldset style="border:1px solid #A6A6A6;border-radius:6px;width:990px;margin:0 auto;margin-top:8px;height:205px;">
	 <legend style="font-size:17px">挂号信息</legend>
	   <form id="form-mregistr" method="post" >
        <div class="medicregister1">
	       	  <a style="margin-left: 10px;">
	       	       <span style="margin-right:7px;">医疗卡号</span>
					<input id="cliniccardid" name="cliniccardid" class="easyui-searchbox" data-options="width:140,height:30,required:true">
		  	  </a> 
		  	  
		  	  <a style="margin-left:40px;">
					<span style="margin-right:7px;">患者姓名</span>
					<input id="ucliickuname" name="ucliickuname" class="easyui-textbox" data-options="width:140,height:30,required:true,readonly:true">
			 </a>
		  	  
		  	  <a style="margin-left:40px;">
				  	  <span style="margin-right:7px;">患者性别</span>
					 <span class="uclick-usexbox">
					 <select id="uclick-usex" name="uclick-usex" class="easyui-combobox"   data-options=" panelHeight:'auto'" style="width: 100px;height: 30px;line-height: 30px;border-radius: 5px;">
						   <option selected="selected">男</option>
						   <option>女</option>
					</select>
					</span>
			  </a>
			  
			  <a style="margin-left:40px;">
					<span style="margin-right:7px;">身份证号</span>
					<input id="ucliickucard" name="ucliickucar" class="easyui-textbox" data-options="width:140,height:30,required:true,readonly:true">
			 </a>
			  
	    </div><!--medicregister1 -->
	    
	    <div class="clickidbox"  style="margin-top: 35px;">
	           <a style="margin-left:10px;">
					<span style="margin-right:7px;">手机号码</span>
					<input id="ucliickutel" name="ucliick-utel" class="easyui-textbox" data-options="width:140,height:30,required:true">
			 </a>
			 
	  	     <a style="margin-left: 40px;">
	  	             <span style="margin-right:7px;">所挂科室</span>
				 	 <select  id="sections" name="sectionname"  class="easyui-combobox" 
				 	               style="width: 140px;height: 30px;line-height: 30px;border-radius: 5px;">
				 	               
					 </select>
					 
					<%--  <span style="margin-right:7px;">所挂科室</span>
	  	          
				 	 <select  id="sections" name="sectionname" 
				 	               style="width: 140px;height: 30px;line-height: 30px;border-radius: 5px;">
				 	           <!--     data-options="panelHeight:100" -->
						<c:forEach  items="${ sectionlist}"   var="s">
						         <option  selected="selected">${s.sectionName }</option>
						</c:forEach>
					 </select> --%>
	  	     </a>			
	    
	        <!--    <a style="margin-left: 40px;">
	           	<span style="margin-right:7px;">医生</span>
				    	<select class="reception-doctor" style="width: 100px;height: 30px;line-height: 30px;border-radius: 5px;">
						   <option>黎明</option>
						   <option>西欧阿米</option>
				    </select>
				</a> -->
				
				 <a style="margin-left:41px;">
			  	  	<span style="margin-right:7px;">挂号类型</span>
					    <select id="registration-type" class="registration-type  easyui-combobox"  name="registrformType" 
					    style="width: 100px;height: 30px;line-height: 30px;border-radius: 5px;"
					    class="easyui-combobox" >
					    </select>
			 </a>
			 
			  <!--  <a style="margin-left:40px;">
					<span style="margin-right:7px;">挂号费用</span>
					<input id="ulookmoney" name="ulookmoney" class="easyui-textbox" style="width:140px,height:30px" value="5">
			           </a> -->
			   
			  <a style="margin-left:40px;">  
			            <span style="margin-right:7px;">付款方式</span>
					    <select onchange="selecttype(this.options[this.options.selectedIndex].value)"   id="moneytype" class="registr-moneytype"  name="registrfrommoneytype" style="width: 140px;height: 30px;line-height: 30px;border-radius: 5px;">
							   <option value="0">医疗卡</option>
							   <option   value="1" selected="selected">现金</option>
					    </select>
			  </a>      
			  <input  id="shyumoneys" class="easyui-textbox" type="hidden"/>  
	    </div> <!-- clickidbox -->
	    
	   <!--  <div style="width:950px; margin: 0 auto;margin-top:20px; font-size:14px; margin-bottom:10px;">
	         <a style="margin-left: 10px;">
	                 <span style="margin-right:7px;">接诊类型</span>
			         <select class="reception"  style="width: 140px;height:30px;line-height:30px;border-radius: 5px;">
					   <option>初诊</option>
					   <option>复诊</option>
			   		 </select>
	         </a>
	    </div> -->
	    <input type="hidden" value="${user.userName}"  name="registrfrom_name" id="registrfrom_name"> 
	     <p style="margin-left:80.5%; margin-top: 42px;">
					<a id="click-yess" style="margin-left:20px;margin-bottom:10px;" class="a easyui-linkbutton"  data-options="iconCls:'icon-ok'">确定</a>
					<a id="click-nos" style="margin-left:20px;margin-bottom:10px;"class="a easyui-linkbutton"  data-options="iconCls:'icon-cancel'">取消</a>
					<!-- <a id="click-ticket" style="margin-left:20px;margin-bottom:10px;"class="a easyui-linkbutton"  data-options="iconCls:'icon-ok'">打印小票</a> -->
		</p>
</form>
</fieldset>	 
	    
	    <!--  所有挂号信息 -->
     <div class="registerationcjy easyui-panel" data-options="fit:true,border:false" >
     <!--   <div class="register-topboxcjy" data-options="fit:true">挂号信息</div> -->
      <fieldset style="border:1px solid #A6A6A6;border-radius:6px;width:990px;margin:0 auto;margin-top:25px;height:202px">
	    <legend style="font-size:17px">挂号记录</legend>
     	    <div class="register2cjy">
	           <!--搜索框 -->
			    <a style="margin-left:5px;">
			    <input id="regsreachbox" class="easyui-searchbox" style="width:200px"
			     data-options="prompt:'请输入患者姓名'"></input>
			    </a>
		      <div style="margin-top:10px;margin-left:5px;margin-bottom:4px;">    
	     	  <table id="registration-tab" class="easyui-datagrid" data-options="fitColumns:false,singleSelect:false,width:930,height:140" >
		    </table>
         </div>	
	    </div><!-- register2-->
   </fieldset>     
      </div><!-- registerationcjy -->
</div>  

<!-- 弹框提示 -->
<div id="saveclinic-winTwo" class="easyui-window"  title="提示框" style="width:300px;height:156px"
    data-options="iconCls:'icon-save',modal:true,resizable:false,collapsible:false,maximizable:false,minimizable:false,closed:true">
          <p class="window-tishi" style=" margin-left:30px;font-size: 16px;margin-top: 47px;">
          </p>
</div>

   <!--   打印小票 -->
     <div id="ticket-registr-win" class="easyui-window" title="打印小票" style="width:755px;height:400px"
	    data-options="iconCls:'icon-save',closed:true,modal:true,shadow:true,resizable:false,collapsible:false,minimizable:false,maximizable:false">
		     <p style="font-size:20px;text-align:center;">XXX医院门诊挂号收据</p>
		     <a style="margin-left:20px;">票据流水单号:
		             <a id="regwaternumber"></a>
		     </a>
		     <a style="margin-left:53%;">票据日期:
		          <a id="regdate"></a>
		      </a>
		    <div style="font-size: 16px;margin-left: 20px;margin-top:35px;">
		         <span style="margin-right:7px;">患者姓名</span>
		         <a id="ticket_uname"style="border-bottom:1px solid #bbb;display: inline-block;width:125px;text-align:center;"></a>
		         <span style="margin-right:7px;margin-left: 50px;">患者性别</span>
		         <a   id="ticket_usex" style="border-bottom:1px solid #bbb;display: inline-block;width:125px;text-align:center;"></a>
		         <span style="margin-right:7px;margin-left: 50px;">所挂科室</span>
		         <a   id="ticket_usection" style="border-bottom:1px solid #bbb;display: inline-block;width:125px;text-align:center;"></a>
		    </div>
		     <div style="font-size: 16px;margin-left: 20px;margin-top:25px;">
		         <span style="margin-right:7px;">挂号类型</span>
		         <a   id="ticket_uregtype" style="border-bottom:1px solid #bbb;display: inline-block;width:125px;text-align:center;"></a>
		         
		         <span style="margin-right:7px;margin-left: 50px;">挂号费用</span>
		         <a id="ticket_umoney"style="border-bottom:1px solid #bbb;display: inline-block;width:125px;text-align:center;"></a>
		         
		          <span style="margin-right:7px;margin-left: 50px;">看诊费用</span>
		         <a id="ticket_ulookmoney"style="border-bottom:1px solid #bbb;display: inline-block;width:125px;text-align:center;"></a>
		    </div>
		    <div style="font-size: 18px;margin-left: 82%; margin-top:9%;">
		         <span style="color:red;">共计：</span>
		         <a id="ticket_utotalmoney"style="display: inline-block;text-align:center;color:red;"></a>
		    </div>
		     <div style="font-size: 16px;margin-left: 82%; margin-top:15px;">
		         <span>经办人：</span>
		         <a id="ticket_uregpeople"style="display: inline-block;text-align:center;"></a>
		    </div>
		
      </div>
</body>
</html>